package com.ysd.lis.service.qc.impl;

import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.yulichang.wrapper.MPJLambdaWrapper;
import com.ysd.common.Result;
import com.ysd.lis.entity.qc.QcCommonRemark;
import com.ysd.lis.mapper.qc.QcCommonRemarkMapper;
import com.ysd.lis.request.qc.QcCommonRemarkDto;
import com.ysd.lis.request.qc.QcCommonRemarkParam;
import com.ysd.lis.service.qc.QcCommonRemarkService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;


/**
 * <p>
 * cold_chain.t_user 服务实现类
 * </p>
 *
 * @author peng
 * @since 2024-01-30
 */
@Service
@Slf4j
public class QcCommonRemarkServiceImpl extends ServiceImpl<QcCommonRemarkMapper, QcCommonRemark> implements QcCommonRemarkService {

    @Autowired
    QcCommonRemarkMapper qcCommonRemarkMapper;
    @Override
    public Result findCommonRemarkList(QcCommonRemarkParam param) {
        MPJLambdaWrapper<QcCommonRemark> queryWrapper = new MPJLambdaWrapper<>();
        queryWrapper.selectAll(QcCommonRemark.class);
        if (StringUtils.isNotBlank(param.getInstrId())) {
            queryWrapper.eq(QcCommonRemark::getInstrId,param.getInstrId());
        }
        if(StringUtils.isNotBlank(param.getInfoType())){
            queryWrapper.eq(QcCommonRemark::getInfoType,param.getInfoType());
        }
        queryWrapper.eq(QcCommonRemark::getDelFlag, 0)
                .orderByAsc(QcCommonRemark::getSeq);
        return Result.succ(1, "查询成功", qcCommonRemarkMapper.selectList(queryWrapper));
    }

    @Override
    public Result saveOrUpdateCommonRemark(QcCommonRemarkDto dto) {
        List<QcCommonRemark> qcCommonRemarkList = dto.getQcCommonRemarkList();
        boolean b = this.saveOrUpdateBatch(qcCommonRemarkList);
        if(b){
            return Result.succ(1, "成功", null);
        }else {
            return Result.fail(400,"失败","");
        }
    }
    @Override
    public Result batchDeleteCommonRemarkList(QcCommonRemarkDto dto) {
        List<QcCommonRemark> qcCommonRemarkList = dto.getQcCommonRemarkList();
        List<String> ids = qcCommonRemarkList.stream().map(QcCommonRemark::getId).collect(Collectors.toList());
        boolean b = this.removeByIds(ids);
        if(b){
            return Result.succ(1, "删除成功", null);
        }else {
            return Result.fail(400,"删除失败","");
        }
    }
}
